<?php
		
		if ($_FILES["file"]["error"] > 0)
		{
			echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
		}
		else
		{
			$dir = "./image/screen";
			$counter_file = "$dir/counter.txt";
			$max = 100;
			
			$counter = file_get_contents( $counter_file );
			$counter--;
			if( $counter <= 0 ){
				for( $i = 1; $i <= $max; $i++){
					$screen_file = "$dir/screen_" . str_pad( $i , 5, "0", STR_PAD_LEFT) . ".jpg";
					if( file_exists($screen_file) ) unlink($screen_file);
				}				
				$counter = $max;
			}
			file_put_contents( $counter_file, $counter );
			
			$screen_file = "$dir/screen_" . str_pad( $counter , 5, "0", STR_PAD_LEFT) . ".jpg";			
			move_uploaded_file($_FILES["file"]["tmp_name"], $screen_file );
			echo $screen_file;
		}
	
?>
